package com.eduhzy.ttw.teacher.mvp.ui.activity;

import android.content.Intent;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.view.View;
import android.widget.TextView;
import android.widget.Toast;

import com.alibaba.android.arouter.facade.annotation.Autowired;
import com.alibaba.android.arouter.facade.annotation.Route;
import com.alibaba.android.arouter.launcher.ARouter;
import com.eduhzy.ttw.commonres.utils.RxUtil;
import com.eduhzy.ttw.commonsdk.core.Constants;
import com.eduhzy.ttw.commonsdk.core.RouterHub;
import com.eduhzy.ttw.commonsdk.entity.ClassDetailsData;
import com.eduhzy.ttw.teacher.R;
import com.eduhzy.ttw.teacher.app.utils.RxUtils;
import com.jess.arms.base.BaseActivity;
import com.jess.arms.di.component.AppComponent;
import com.jess.arms.mvp.IView;
import com.jess.arms.utils.ArmsUtils;
import com.qmuiteam.qmui.widget.QMUIRadiusImageView;

import butterknife.BindView;
import butterknife.OnClick;

import static com.jess.arms.utils.Preconditions.checkNotNull;

/**
 * 班级创建成功
 *
 * @author xubo
 */
@Route(path = RouterHub.APP_CREATECLASSSUCCESSACTIVITY)
public class CreateClassSuccessActivity extends BaseActivity implements IView {

    @BindView(R.id.iv_avatar)
    QMUIRadiusImageView ivAvatar;
    @BindView(R.id.tv_name)
    TextView tvName;
    @BindView(R.id.tv_sid)
    TextView tvSid;
    @BindView(R.id.tv_grade)
    TextView tvGrade;
    @BindView(R.id.tv_creator)
    TextView tvCreator;

    @Autowired(name = Constants.ROUTER_DATA)
    ClassDetailsData data;

    @Override
    public void setupActivityComponent(@NonNull AppComponent appComponent) {

    }

    @Override
    public int initView(@Nullable Bundle savedInstanceState) {
        //如果你不需要框架帮你设置 setContentView(id) 需要自行设置,请返回 0
        return R.layout.activity_create_class_success;
    }

    @Override
    public void initData(@Nullable Bundle savedInstanceState) {
        tvName.setText(data.getBjmc());
        tvSid.setText(data.getBaseNo());
        tvGrade.setText(data.getNjmc());
        tvCreator.setText(data.getBzrName());
    }

    @Override
    public void showLoading() {

    }

    @Override
    public void hideLoading() {

    }

    @Override
    public void showMessage(@NonNull String message) {
        checkNotNull(message);
        Toast.makeText(this, message, Toast.LENGTH_SHORT).show();
    }

    @Override
    public void launchActivity(@NonNull Intent intent) {
        checkNotNull(intent);
        ArmsUtils.startActivity(intent);
    }

    @Override
    public void killMyself() {
        finish();
    }


    @OnClick({R.id.iv_qr_code, R.id.btn_join})
    public void onViewClicked(View v) {
        switch (v.getId()) {
            case R.id.iv_qr_code:
                ARouter.getInstance().build(RouterHub.APP_GENERATECODEACTIVITY)
                        .withString(Intent.EXTRA_TITLE, Constants.CLASS_QRCODE)
                        .withString(Constants.GENERATE_CODE, RxUtil.getClassCode(data.getBaseNo()))
                        .withInt(Constants.QR_CODE_TYPE, Constants.QRCODE.Clazz)
                        .navigation(CreateClassSuccessActivity.this);
                break;
            case R.id.btn_join:
                RxUtils.showShareQRMenu(this,RxUtil.getClassCode(data.getBaseNo()));
                break;
            default:
        }
    }
}
